package Threelayer.Utils;

import javax.tools.JavaCompiler;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @author lishunlin110
 * @version 1.0
 * @description: 日期转换工具
 * @date 2021/8/23 12:05
 */
public class DateUtils {

     private static final SimpleDateFormat SDF=new SimpleDateFormat("yyyy-MM-dd");
    //1.字符串转换为util.Date
    public static java.util.Date strToUtil(String str){
        try {
            return SDF.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    //2.util.Date ->sql.Date
    public static java.sql.Date utilToSql(java.util.Date date){
        return new  java.sql.Date(date.getTime());
    }

    //3.util.Date ->string
    public static String utilToStr(java.util.Date date){
        return SDF.format(date);
    }
}
